﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace MvcEngine.Core.Configuration
{
    public class FoldersConfigurationCollection : ConfigurationElementCollection
    {
        public FolderConfigurationElement this[int index]
        {
            get
            {
                return base.BaseGet(index) as FolderConfigurationElement;
            }
            set
            {
                if (base.BaseGet(index) != null)
                {
                    base.BaseRemoveAt(index);
                }
                this.BaseAdd(index, value);
            }
        }

        public new string this[string folder]
        {
            get
            {
                for (int i = 0; i < this.Count; i++)
                {
                    if (this[i].Folder == folder)
                        return this[i].Path;
                }
                throw new ArgumentException("Folder " + folder + " was not found in web.config");
            }
        }

        protected override ConfigurationElement CreateNewElement()
        {
            return new FolderConfigurationElement();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((FolderConfigurationElement)element).Folder;
        }
    }
}
